/**********舟山海味（食物）路由器************************/
const express = require('express')
const res = require('express/lib/response')
const pool = require('../pool.js')
const router = express.Router()
module.exports = router

//1.添加一个查询所有食物的接口
//GET /show
//测试地址:http://127.0.0.1:8080/v1/food/show
router.get('/show',(req,res)=>{
	let sql = 'select * from food'
	pool.query(sql,(err,result)=>{
		if(err) throw err 
		res.send(result)
	})
})

//2.添加一个查询指定数量食物饭店的接口
//GET /list 
//请求参数 pageSize=3
//测试地址:http://127.0.0.1:8080/v1/food/list?pageSize=3
router.get('/list',(req,res)=>{
	let ps = req.query.pageSize
	ps = ps?parseInt(ps):5
	let sql = 'select * from food limit ?'
	pool.query(sql,ps,(err,result)=>{
		if(err) throw err 
		res.send(result)
	})
})

//3.添加一个查询指定分类海味的接口
//GET /classShow
//请求参数:class_id=10       10-海鲜排挡  20-酒楼饭店  30-风味小吃  40-舟山心意
//请求地址:http://127.0.0.1:8080/v1/food/classShow?class_id=10
router.get('/classShow',(req,res)=>{
	let cid = req.query.class_id
	cid = parseInt(cid)
	let sql = 'select * from food where class_id=?'
	pool.query(sql,cid,(err,result)=>{
		if(err) throw err
		res.send(result)
	})
})

// 4.添加一个查询一个指定饭店的接口
// GET  /food_detail
// 请求参数:fid=1 
// 接口地址: http://127.0.0.1:8080/v1/food/food_detail?fid=1
router.get('/food_detail',(req,res)=>{
	let id = req.query.fid
	let sql = 'select * from food where fid=?'
	pool.query(sql,id,(err,result)=>{
		if(err) throw err
		res.send(result)
	})
})